package org.starsource.forum.client.util;

import java.util.ArrayList;
import java.util.List;

import org.starsource.forum.client.domain.ResourceObject;
import org.starsource.forum.shared.util.ImageTypeHelper;

public class ImageFilter implements Filter<List<ResourceObject>> {
	
	private final Constraint<ResourceObject> constraint = new Constraint<ResourceObject>() {

		@Override
		public boolean isSatisfied(ResourceObject object) {
			return ImageTypeHelper.isImage(object.getUrl());
		}
		
	};
	
	@Override
	public List<ResourceObject> getSatisfied(List<ResourceObject> collection) {
		List<ResourceObject> ResourceObjects = new ArrayList<ResourceObject>();
		for(int index = 0; index < collection.size(); index ++) {
			if (constraint.isSatisfied(collection.get(index))) {
				ResourceObjects.add(collection.get(index));
			}
		}
		return ResourceObjects;
	}

	@Override
	public List<ResourceObject> getUnsatisfied(List<ResourceObject> collection) {
		List<ResourceObject> ResourceObjects = new ArrayList<ResourceObject>();
		for(int index = 0; index < collection.size(); index ++) {
			if (!constraint.isSatisfied(collection.get(index))) {
				ResourceObjects.add(collection.get(index));
			}
		}
		return ResourceObjects;
	}
}
